from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-08 14:02:29.412541
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 08, Dec, 2022
Time: 14:02:34
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.1594
Nobs: 864.000 HQIC: -51.4655
Log likelihood: 11371.5 FPE: 3.68428e-23
AIC: -51.6554 Det(Omega_mle): 3.32180e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.294580 0.050016 5.890 0.000
L1.Burgenland 0.106202 0.034206 3.105 0.002
L1.Kärnten -0.107396 0.018345 -5.854 0.000
L1.Niederösterreich 0.215380 0.071808 2.999 0.003
L1.Oberösterreich 0.089528 0.068093 1.315 0.189
L1.Salzburg 0.249425 0.036323 6.867 0.000
L1.Steiermark 0.030382 0.047697 0.637 0.524
L1.Tirol 0.129629 0.038759 3.344 0.001
L1.Vorarlberg -0.063507 0.033366 -1.903 0.057
L1.Wien 0.059957 0.060883 0.985 0.325
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.065105 0.103046 0.632 0.528
L1.Burgenland -0.008986 0.070472 -0.128 0.899
L1.Kärnten 0.050475 0.037795 1.335 0.182
L1.Niederösterreich -0.175122 0.147942 -1.184 0.237
L1.Oberösterreich 0.369380 0.140288 2.633 0.008
L1.Salzburg 0.286080 0.074834 3.823 0.000
L1.Steiermark 0.109892 0.098267 1.118 0.263
L1.Tirol 0.311829 0.079853 3.905 0.000
L1.Vorarlberg 0.024924 0.068742 0.363 0.717
L1.Wien -0.027389 0.125434 -0.218 0.827
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.198441 0.025886 7.666 0.000
L1.Burgenland 0.090206 0.017703 5.095 0.000
L1.Kärnten -0.008666 0.009495 -0.913 0.361
L1.Niederösterreich 0.266992 0.037165 7.184 0.000
L1.Oberösterreich 0.116758 0.035242 3.313 0.001
L1.Salzburg 0.052481 0.018799 2.792 0.005
L1.Steiermark 0.016469 0.024686 0.667 0.505
L1.Tirol 0.099238 0.020060 4.947 0.000
L1.Vorarlberg 0.056073 0.017269 3.247 0.001
L1.Wien 0.113073 0.031510 3.588 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105488 0.026566 3.971 0.000
L1.Burgenland 0.047680 0.018168 2.624 0.009
L1.Kärnten -0.016472 0.009744 -1.691 0.091
L1.Niederösterreich 0.196133 0.038140 5.142 0.000
L1.Oberösterreich 0.280935 0.036167 7.768 0.000
L1.Salzburg 0.118230 0.019292 6.128 0.000
L1.Steiermark 0.100856 0.025334 3.981 0.000
L1.Tirol 0.123977 0.020586 6.022 0.000
L1.Vorarlberg 0.069393 0.017722 3.916 0.000
L1.Wien -0.027058 0.032337 -0.837 0.403
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131004 0.048069 2.725 0.006
L1.Burgenland -0.053463 0.032874 -1.626 0.104
L1.Kärnten -0.037333 0.017631 -2.118 0.034
L1.Niederösterreich 0.167719 0.069012 2.430 0.015
L1.Oberösterreich 0.134667 0.065442 2.058 0.040
L1.Salzburg 0.290745 0.034909 8.329 0.000
L1.Steiermark 0.034135 0.045840 0.745 0.456
L1.Tirol 0.162819 0.037250 4.371 0.000
L1.Vorarlberg 0.107333 0.032067 3.347 0.001
L1.Wien 0.064007 0.058513 1.094 0.274
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059604 0.038058 1.566 0.117
L1.Burgenland 0.038378 0.026028 1.475 0.140
L1.Kärnten 0.049627 0.013959 3.555 0.000
L1.Niederösterreich 0.226883 0.054640 4.152 0.000
L1.Oberösterreich 0.273257 0.051813 5.274 0.000
L1.Salzburg 0.058294 0.027638 2.109 0.035
L1.Steiermark -0.006971 0.036293 -0.192 0.848
L1.Tirol 0.158313 0.029492 5.368 0.000
L1.Vorarlberg 0.068533 0.025389 2.699 0.007
L1.Wien 0.074764 0.046327 1.614 0.107
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183922 0.045689 4.026 0.000
L1.Burgenland 0.016732 0.031246 0.535 0.592
L1.Kärnten -0.060381 0.016758 -3.603 0.000
L1.Niederösterreich -0.093091 0.065595 -1.419 0.156
L1.Oberösterreich 0.184372 0.062201 2.964 0.003
L1.Salzburg 0.059080 0.033180 1.781 0.075
L1.Steiermark 0.228408 0.043570 5.242 0.000
L1.Tirol 0.488109 0.035405 13.786 0.000
L1.Vorarlberg 0.051770 0.030479 1.699 0.089
L1.Wien -0.056950 0.055615 -1.024 0.306
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158284 0.051892 3.050 0.002
L1.Burgenland 0.000059 0.035489 0.002 0.999
L1.Kärnten 0.066758 0.019033 3.507 0.000
L1.Niederösterreich 0.200409 0.074501 2.690 0.007
L1.Oberösterreich -0.068855 0.070647 -0.975 0.330
L1.Salzburg 0.220708 0.037685 5.857 0.000
L1.Steiermark 0.113197 0.049486 2.287 0.022
L1.Tirol 0.083142 0.040213 2.068 0.039
L1.Vorarlberg 0.123194 0.034617 3.559 0.000
L1.Wien 0.104709 0.063167 1.658 0.097
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357709 0.030633 11.677 0.000
L1.Burgenland 0.006407 0.020949 0.306 0.760
L1.Kärnten -0.024344 0.011235 -2.167 0.030
L1.Niederösterreich 0.227626 0.043979 5.176 0.000
L1.Oberösterreich 0.158371 0.041703 3.798 0.000
L1.Salzburg 0.052379 0.022246 2.355 0.019
L1.Steiermark -0.015817 0.029212 -0.541 0.588
L1.Tirol 0.116826 0.023738 4.921 0.000
L1.Vorarlberg 0.072269 0.020435 3.537 0.000
L1.Wien 0.050029 0.037288 1.342 0.180
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038056 0.156529 0.179007 0.166498 0.139276 0.122962 0.064698 0.219814
Kärnten 0.038056 1.000000 0.000600 0.131495 0.026434 0.098487 0.431739 -0.049708 0.102161
Niederösterreich 0.156529 0.000600 1.000000 0.343762 0.168482 0.310119 0.124701 0.191147 0.341794
Oberösterreich 0.179007 0.131495 0.343762 1.000000 0.233727 0.340117 0.176137 0.178988 0.273755
Salzburg 0.166498 0.026434 0.168482 0.233727 1.000000 0.151819 0.135508 0.152735 0.142013
Steiermark 0.139276 0.098487 0.310119 0.340117 0.151819 1.000000 0.156592 0.147592 0.093515
Tirol 0.122962 0.431739 0.124701 0.176137 0.135508 0.156592 1.000000 0.120692 0.168125
Vorarlberg 0.064698 -0.049708 0.191147 0.178988 0.152735 0.147592 0.120692 1.000000 0.020339
Wien 0.219814 0.102161 0.341794 0.273755 0.142013 0.093515 0.168125 0.020339 1.000000